package TSV_1990;

import com.google.common.util.concurrent.CycleDetectingLockFactory;
import org.openqa.selenium.*;
import org.openqa.selenium.support.ui.*;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;


/**
 * Created with IntelliJ IDEA.
 * User: Vitalik
 * Date: 10.11.13
 * Time: 0:37
 * To change this template use File | Settings | File Templates.
 */
public class tsv_test {




    public WebDriver driver;
    public WebElement query;
    public String user = "test_8009@gmail.com",
                  pass =" qwerty+";

    @Test


    public void test_registration()
    {
        System.out.println("LOGIN: "+user);
        System.out.println("PASS: "+ pass);
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("http://buxfer.com/");
        WebDriverWait wait = new WebDriverWait(driver, 15) ;
        //**********************************************************
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"login_form\"]/div[1]/table/tbody/tr/td[3]/table/tbody/tr[2]/td/div/a")));
            query = driver.findElement(By.xpath("//*[@id=\"login_form\"]/div[1]/table/tbody/tr/td[3]/table/tbody/tr[2]/td/div/a"));
            query.click();
        wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"__pageBody\"]/div[2]/div[3]/div/div[2]/a")));
            driver.findElement(By.xpath("//*[@id=\"__pageBody\"]/div[2]/div[3]/div/div[2]/a")).click();
        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("signup_password")));
        //********send log info*********************
           driver.findElement(By.id("signupEmail")).sendKeys(user);
           driver.findElement(By.id("signup_password")).sendKeys(pass);
                wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"signup_table\"]/tbody/tr[5]/td[2]/div[1]/table/tbody/tr[2]/td/div/a")));
               driver.findElement(By.xpath("//*[@id=\"signup_table\"]/tbody/tr[5]/td[2]/div[1]/table/tbody/tr[2]/td/div/a")).click();
        //***************Check for registration*******
         /*wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"signup_errordiv\"]")));
        query = driver.findElement(By.xpath("//*[@id=\"signup_errordiv\"]")) ;
        System.out.println(query.getText());

        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("signup_errordiv")));
            if(query.findElement(By.xpath("//*[@id=\"signup_errordiv\"]")).isDisplayed()) {
                System.out.println(query.getText());
                assert (false):"This email address is already registered.Test FAIL  "; } */
        //*******************************************************************************
        wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@id=\"overlay\"]/table/tbody/tr[3]/td/div[1]")));
        query = driver.findElement(By.xpath("//*[@id=\"overlay\"]/table/tbody/tr[3]/td/div[1]"));

        if (query.getText() == user)  {assert (false): "test#2_register FAIL";}
        else {
            System.out.println("Registration - PASS") ;
            wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//*[@id=\"id-7-7e461\"]/div")));
            query.findElement(By.xpath("//*[@id=\"id-7-7e461\"]/div")).click();
            driver.
        }
        driver.quit();

    }
        //signup_indicator - id xfcbrjd
  //  @AfterSuite
  // public void class  after
    //{
    //if (driver!=null ) driver.quit();
    //}
}


